package com.example.gateway.conf;

import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class GateWayConfig {
  @Bean
  public RouteLocator routeLocatorConfig(RouteLocatorBuilder builder) {

    return builder
        .routes()
        .route(
            r ->
                r.path("/employee/**")
                    .filters(
                        f ->
                            f.hystrix(
                                h ->
                                    h.setName("Hystrix")
                                        .setFallbackUri("forward:/fallback/message")))
                    .uri("lb://EMPLOYEE-SERVICE")
                    .id("employeeModule"))
        .route(
            r ->
                r.path("/consumer/**")
                    .filters(
                        f ->
                            f.hystrix(
                                h ->
                                    h.setName("Hystrix")
                                        .setFallbackUri("forward:/fallback/message")))
                    .uri("lb://CONSUMER-SERVICE")
                    .id("consumerModule"))
        .build();
  }
}
